#include<iostream>
#include<deque>
using namespace std;
typedef long long LL;
const int N = 1e7 + 10;
int a[N], f[N];
int n, m;
deque<int> q;
int main()
{
	cin >> n >> m;
	for (int i = 1;i <= n;i++)
	{
		int x = 0;
		cin >> x;
		f[i] = f[i - 1] + x;
	}
	//限制必须相差三个
	int ret = -1e6;
	int l = 0, r = 0;
	//for (l = 0;l < n;l++)
	//{
	//	for (r = l + 1;r <= n&&r<=l+m;r++)
	//	{
	//		ret = max(ret, f[r] - f[l]);
	//	}
	//}
	//上面的超时，我们用单调队列来优化
	q.push_back(f[0]);
	for (int i = 1;i <= n;i++)
	{
		//判断一下超没超m个
		while (q.size()&&i - q.front() > m) q.pop_front();
		ret = max(ret, f[i] - f[q.front()]);
		//单调队列
		while (q.size() && f[i] <= f[q.back()]) q.pop_back();
		q.push_back(i);

	}
	//单调队列也可以用数组来写
	//while (head <= tail && q[head] < i - m) head++;//已经不在范围内要出队 
	//ans = max(ans, sum[i] - sum[q[head]]);
	//while (head <= tail && sum[i] <= sum[q[tail]]) tail--;//维护单调递增的队列 
	//q[++tail] = i;
	printf("%d", ret);
	return 0;
}